const express = require('express');
const path = require("path");
//创建express对象
const app = express();
const port = 8080;

//开放静态资源文件夹
app.use(express.static('public'));

//get请求，拦截的地址是/
app.get('/', (req, res) => {
    //响应
    res.send('Hello World!');
});
app.post('/', (req, res) => {
    //响应
    res.send('Hello World!');
});

app.get('/demo.html', (req, res) => {
    //响应
    // res.send('Hello World!');
    res.sendFile(path.join(__dirname, "demo.html"));
});

//启动服务器，并监听端口号
app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
});